<?php

/**
 * Description of Az_Options
 * 
 * @author Shark
 */
class Az_Options {

    var $id;
    var $option_name;
    var $option_type;
    var $data;
    var $descr;
    var $active;
    var $nametbl = 'az_option_value';

    public function __construct() {
        
    }

    /*
     * Create function option
     */

    function create_option($_id, $_optionname, $_optiontype, $_data, $_descr, $_active) {
        $this->id = $_id;
        $this->option_name = $_optionname;
        $this->option_type = $_optiontype;
        $this->data = $_data;
        $this->descr = $_descr;
        $this->active = $_active;
    }

    /*
     * Function add option value
     */

    function add_option() {
        if ($this->option_name != '' && $this->option_type != '' && $this->data != '') {
            global $az_db;
            $sql = "INSERT INTO " . $this->nametbl .
                    "(`option_name`,`option_type`,`data`,`description`,`active`)" .
                    "VALUES(?,?,?,?,?)";
            $params = array($this->option_name, $this->option_type, $this->data, $this->descr, $this->active);
            if ($az_db->executeStmt_Az($sql, 'ssssi', $params)) {
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    /*
     * Function update option
     */

    function update_option() {
        global $az_db;
        if ($this->option_name != '' && $this->data !='') {
            $type_format = '';
            $params = array();
            $sql = "UPDATE " . $this->nametbl . " SET option_name=?";
            $type_format .='s';
            array_push($params, $this->option_name);

            if ($this->option_type != '') {
                $sql .= ",option_type=?";
                $type_format .='s';
                array_push($params, $this->option_type);
            }

            //Set update data
            $sql .=",data=?";
            $type_format .='s';
            array_push($params, $this->data);

            if ($this->descr != '') {
                $sql .=",description=?";
                $type_format .='s';
                array_push($params, $this->descr);
            }

            if ($this->active != '' && is_numeric($this->active)) {
                $sql.=",active=?";
                $type_format .='i';
                array_push($params, $this->active);
            }

            //where clause
            $sql.=" WHERE id=?";
            $type_format .='i';
            array_push($params, $this->id);
            return $az_db->executeStmt_Az($sql, $type_format, $params);
        }
    }

    /*
     * Function delete option
     */

    function delete_option($option_id) {
        global $az_db;   
        $sql = "DELETE FROM " . $this->nametbl . " WHERE `id`=" . $option_id;
        return $az_db->executeSQL_Query($sql);
    }

    /*
     * Save to xml file option
     */

    function save_xml_option() {
        
    }

    /*
     * Update xml option
     */

    function update_xml_option() {
        
    }

    /*
     * Funciton to delete xml option value
     */

    function delete_xml_option() {
        
    }

}

?>
